package com.youku.expression.ast;

import com.youku.expression.Token;

public class OpNEAst extends OpAst {

	public OpNEAst(Token op, Ast exp1, Ast exp2) {
		super(op, exp1, exp2);
	}

	@Override
	protected Object operate(Object left, Object right) {
		if (left instanceof Number && right instanceof Number) {
			Number op1 = (Number) left;
			Number op2 = (Number) right;
			if (op1 instanceof Double || op2 instanceof Double) {
				return op1.doubleValue() != op2.doubleValue();
			} else if (op1 instanceof Float || op2 instanceof Float) {
				return op1.floatValue() != op2.floatValue();
			} else if (op1 instanceof Long || op2 instanceof Long) {
				return op1.longValue() != op2.longValue();
			} else {
				return op1.intValue() != op2.intValue();
			}
		}

		if (left != null && (left instanceof Comparable)) {
			return getTypeComparator().compare(left, right) != 0;
		} else {
			return left != right;
		}
	}

}
